package leetcode.题库.数组.普通数组;

/**
 * description:
 *
 * @author 颜真明
 * @date 2024/3/20  18:49
 */
public class Solution215 {


    public static void main(String[] args) {

//        ThreadLocal threadLocal = new ThreadLocal();
//        WeakReference<ThreadLocal> threadLocalWeakReference = new WeakReference<>(threadLocal);
//
//        int[] nums = new int[]{3,2,1,5,6,4};
//        System.out.println(findKthLargest(nums, 2));
        String s = new String("abcdefg");
        s.substring(2);
        System.out.println(s.substring(2));
    }

    public static int findKthLargest(int[] nums, int k) {
        return findK(nums, 0, nums.length -1, k);
    }

    public static int findK(int[] arr, int left, int right, int k){
        if (left >= right) {
            return 0;
        }
        // 以第一个数为基点，找到第一个小于基点的数
        int base = 0;
        for (int i = right-1; i >= left; i--) {
            if (arr[i] < arr[left]) {
                base = i;
                int temp = arr[0];
                arr[0] = arr[base];
                arr[base] = temp;
                break;
            }
        }

        if (k + base == arr.length) {
            return arr[base];
        }
        findK(arr, left, base-1, k);
        findK(arr, base+1, right, k);
        return 0;
    }


}
